/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            storeAdsManageInfo: {
                storeAdss: [],
                total: 0,
                records: 1,
                adTypes: [],
                adsId: '',
                conditions: {
                    adName: '',
                    adType: '',
                    advertType: '',
                    shopId: ''
                }
            }
        },
        _initMethod: function () {
            $that._listStoreAdss(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('store_ads', "ad_type", function (_data) {
                $that.storeAdsManageInfo.adTypes = _data;
            });
        },
        _initEvent: function () {
            vc.on('storeAdsManage', 'listStoreAds', function (_param) {
                $that._listStoreAdss(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listStoreAdss(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listStoreAdss: function (_page, _rows) {
                $that.storeAdsManageInfo.conditions.page = _page;
                $that.storeAdsManageInfo.conditions.row = _rows;
                $that.storeAdsManageInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                
                let param = {
                    params: $that.storeAdsManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/mallAd.listMallAd',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.storeAdsManageInfo.total = _json.total;
                        $that.storeAdsManageInfo.records = _json.records;
                        $that.storeAdsManageInfo.storeAdss = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.storeAdsManageInfo.records,
                            dataCount: $that.storeAdsManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddStoreAdsModal: function () {
                vc.emit('addStoreAds', 'openAddStoreAdsModal', {});
            },
            _openEditStoreAdsModel: function (_storeAds) {
                vc.emit('editStoreAds', 'openEditStoreAdsModal', _storeAds);
            },
            _openDeleteStoreAdsModel: function (_storeAds) {
                vc.emit('deleteStoreAds', 'openDeleteStoreAdsModal', _storeAds);
            },
            //查询
            _queryStoreAdsMethod: function () {
                $that._listStoreAdss(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetStoreAdsMethod: function () {
                $that.storeAdsManageInfo.conditions.adName = "";
                $that.storeAdsManageInfo.conditions.adType = "";
                $that.storeAdsManageInfo.conditions.advertType = "";
                $that._listStoreAdss(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.storeAdsManageInfo.moreCondition) {
                    $that.storeAdsManageInfo.moreCondition = false;
                } else {
                    $that.storeAdsManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
